package demo04

/**
 * @author xiaoZhao
 * @date 2022/6/29
 * @describe
 */
object Test08_Practice {
  def main(args: Array[String]): Unit = {
    // 练习1
    val fun = (i: Int, S: String, c: Char) => {
      if (i == 0 && S == " " && c == '0') false else true
    }

    println(fun(0, " ", '0'))
    println(fun(0, " ", '1'))
    println(fun(2, " ", '1'))
    println(fun(0, "lisi", '0'))


    // 练习2
    def func(i: Int): String => (Char => Boolean) = {
      def f1(s: String): Char => Boolean = {
        def f2(c: Char): Boolean = {
          if (i == 0 && s == " " && c == '0') false else true
        }
        f2
      }
      f1
    }

    println(func(0)(" ")('0'))
    println(func(2)(" ")('0'))
    println(func(0)(" ")('3'))
    println(func(0)("hello")('3'))

    // 匿名函数的简写
    def func1(i: Int): String => (Char => Boolean) = {
      (s: String) => {
        (c: Char)=> {
          if (i == 0 && s == " " && c == '0') false else true
        }
      }
    }

    // 持续简化
    def func2(i: Int): String => (Char => Boolean) = {
      s => c => if (i == 0 && s == " " && c == '0') false else true
    }

    // 柯里化
    def fun3(i: Int)(s: String)(c: Char): Boolean={
      if (i == 0 && s == " " && c == '0') false else true
    }
  }
}
